#include <string.h>
#include <stdio.h>
#include "cli_api.h"
#include "board_partitions.h"

static void partition_command_usage(const char *prog)
{
    printf("  Usage: %s [OPTIONS]\r\n", prog);
    printf("  Options:\r\n");
    printf("  show                                      Show the flash partitions\r\n");
    printf("\r\n");
}


void partition_cli(char *outbuf, int len, int argc, char **argv)
{
    if (argc == 1) {
        partition_command_usage(argv[0]);
        return;
    }
    if (!strcmp(argv[1], "show")) {
        print_partiton_table();
    } else {
        cli_printf("param invalid!\n");
    }

    return;
}


static const struct cli_command_st partition_cli_cmd[] = 
{
    [0] =
    {
        .name            = "partitions",
        .help            = "partitions [show flash partitions]",
        .function        = partition_cli
    },
};

int partition_cli_register(void) 
{
    int ret = 0;

    ret = cli_register_commands(partition_cli_cmd, sizeof(partition_cli_cmd)/sizeof(struct cli_command_st));
    if (ret != CLI_OK) {
        printf("flash_partition cli register fail\n");
        return ret;
    }

    return CLI_OK;
}